package net.homelinux.chaoswg.io.renga.krypto.animations.Mult;

import javax.swing.JLabel;
import javax.swing.JWindow;

import net.homelinux.chaoswg.io.renga.core.animations.Animation;
import net.homelinux.chaoswg.io.renga.core.animations.State;

public class MultAnimation extends Animation {
    MultState initialState;
    MultStateChanger multChanger;
    
    JLabel firstOperandsDisplay;
    JLabel secondOperandsDisplay;
    JLabel resultDisplay;
    JWindow jw = new JWindow();

    public MultAnimation() {
        initialize(new MultState());
    }
    
    public MultAnimation (MultState state) {
        initialize(state);
    }
    
    private void initialize(State initialState) {
        if (!(initialState instanceof MultState)) {
            throw new IllegalArgumentException ();
        }

        this.initialState = ((MultState)initialState);
        this.multChanger = new MultStateChanger (this.initialState);
    }

    @Override
    public synchronized void start() {
        Thread t = new Thread (multChanger);
        t.setDaemon(true);
        t.start();
        
        try {
            t.join();
        } catch (InterruptedException iexcp){ 
            iexcp.printStackTrace();
        }
        multChanger.close ();
        finished = true;
        setChanged();
        notifyObservers();
    }

    @Override
    public void setOperand(int i, Object operand) {
        initialState.setOperand(i, operand);
    }

}
